package com.jams.goodox.activity.mine;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.facebook.drawee.view.SimpleDraweeView;
import com.jams.goodox.BaseActivity;
import com.jams.goodox.R;
import com.jams.goodox.SePref;
import com.jams.goodox.net.RetrofitCallbackListener;
import com.jams.goodox.net.services.HomeService;
import com.jams.goodox.utils.StyleUtil;
import com.jams.library.fresco.FrescoUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import retrofit2.Call;

/**
 * Created by Administrator on 2017/10/1.
 */

public class HuiyuanActivity extends BaseActivity {
    @Bind(R.id.tx_yajin)
    TextView txYajin;
    @Bind(R.id.recycle_yajin)
    RecyclerView recycleYajin;

    private BaseQuickAdapter baseQuickAdapter;
    private List<HuiyuanBean.Data> dataList;

    @Override
    protected int getLayoutId() {
        return R.layout.huiyuan_activity;
    }

    @Override
    protected void init() {
        StyleUtil.titleBackKey(this, "会员中心");
        initRecycleView();
        getData();
    }

    private void initRecycleView(){
        recycleYajin.setLayoutManager(new LinearLayoutManager(this));
        dataList=new ArrayList<>();
        baseQuickAdapter=new BaseQuickAdapter<HuiyuanBean.Data>(R.layout.huiyuan_item,dataList) {
            @Override
            protected void convert(BaseViewHolder baseViewHolder, HuiyuanBean.Data item) {
                SimpleDraweeView sdv_enterprise_portrait=baseViewHolder.getView(R.id.sdv_enterprise_portrait);
                FrescoUtil.loadNetUrl(sdv_enterprise_portrait,item.getOrderImgUrl());
                baseViewHolder.setText(R.id.tx_order_number,String.format("订单号：%s",item.getOrderNumber()));
                baseViewHolder.setText(R.id.tx_order_money, String.format("%s %s",item.isInmoney()?"+":"-",item.getMoney()));
                baseViewHolder.setText(R.id.tx_order_date,item.getOrderTime());
                baseViewHolder.setText(R.id.tx_order_get,item.isInmoney()?"押金存入":"押金支出");
            }
        };
        recycleYajin.setAdapter(baseQuickAdapter);
    }

    private void getData(){
        enqueue(createCallService(HomeService.class).daybook(SePref.getToken()), new RetrofitCallbackListener<HuiyuanBean>() {
            @Override
            public void onSuccess(Call<HuiyuanBean> call, HuiyuanBean result) {
                dataList.clear();
                dataList.addAll(result.getData());
                baseQuickAdapter.notifyDataSetChanged();
            }

            @Override
            public void onError(String msg) {

            }
        });
    }
}
